var statusGlobal;
var systimeGlobal;
var starttimeGlobal;
var endtimeGlobal;
var q;
var promotionTypeNameGlobal;
var timeInfoTitle;

function clockInit(status,systime,starttime,endtime,promotionTypeName,houseName){
	statusGlobal = status;
	systimeGlobal = systime;
	starttimeGlobal = starttime;
	endtimeGlobal = endtime;
	promotionTypeNameGlobal = promotionTypeName;
	
	if(''!=houseName && promotionTypeNameGlobal == '抢购'){
	 $('#choosed-area').html(houseName);
     $('#area-selector span').text(houseName);
	}
     
	var DisplayMsg  = {
		date:{
			wait:'开始',
			start:"结束",
			out:"结束"
		},
		show:function(type){
			return DisplayMsg.date[type];
		}
	};

	timeInfoTitle = promotionTypeNameGlobal + DisplayMsg.show(statusGlobal);
	
	$('#promotionStatus').attr('class',getPromotionStatusClass());
	if(statusGlobal=='out'){
		//$('#promotionStatus').removeAttr('href');
		$('#promotionStatus').attr('href', 'javascript:void(0);');
	}
	q= window.setInterval("show_date_time()", 1000);
}

function getPromotionStatusClass(){
	promotionStatus = 'buy';
	
	if(statusGlobal=='start'){
		if(promotionTypeNameGlobal == '秒杀' || promotionTypeNameGlobal == '福袋'){
			promotionStatus = 'miaosha';
		}else if(promotionTypeNameGlobal == '抢购' || promotionTypeNameGlobal == 'VIP抢购'){
			promotionStatus = 'qianggou';
		}else if (promotionTypeNameGlobal=='拍卖') {
			promotionStatus = 'proAuctionStart btn-buy';
		}
	}else if(statusGlobal=='out'){
		if(promotionTypeNameGlobal == '秒杀' || promotionTypeNameGlobal == '福袋'){
			promotionStatus = 'miaoshaEnd';
		}else if (promotionTypeNameGlobal=='拍卖') {
			promotionStatus = 'proAuctionEnd';
		}else {//if(promotionTypeNameGlobal == '抢购' || promotionTypeNameGlobal == 'VIP抢购'){
			promotionStatus = 'qianggouEnd';
		}
	}
	
	return promotionStatus;
}

function show_date_time() {
	var targetTime;
	if(statusGlobal=='wait'){
		targetTime = starttimeGlobal;
	}else if(statusGlobal=='start' || statusGlobal=='out'){
		targetTime = endtimeGlobal;
	}else{//活动结束
		window.location.reload();
		return;
	}
	
	var timeold = (targetTime - systimeGlobal);
	
	if (timeold <= 0) {
			window.location.reload();
			return ;
	}
	
	if ((timeold<=1000*60*5) && (promotionTypeNameGlobal=='拍卖')){
		$(".proAuctionText").show();
	}
	
	sectimeold = timeold / 1000;
	systimeGlobal=systimeGlobal+1000;
	secondsold = Math.floor(sectimeold);
	msPerDay = 24 * 60 * 60 * 1000;
	e_daysold = timeold / msPerDay;
	daysold = Math.floor(e_daysold);//天
	e_hrsold = (e_daysold - daysold) * 24;
	hrsold = Math.floor(e_hrsold);//小时
	e_minsold = (e_hrsold - hrsold) * 60;
	minsold = Math.floor((e_hrsold - hrsold) * 60);//分
	e_seconds = (e_minsold - minsold) * 60;
	seconds = Math.floor((e_minsold - minsold) * 60);//秒
	
//	timeInfo = "距离"+timeInfoTitle+":"+"<br /><span><b id='hour'>"+(hrsold < 10 ? '0' + hrsold : hrsold)+
//	"</b>:<b id='min'>"+(minsold < 10 ? '0' + minsold : minsold)+"</b>:<b id='sec'>"+(seconds < 10 ? '0' + seconds : seconds)+"</b></span>";
	timeInfo = '距离{title}：<br><span><b>{day}</b><em class="tim-fontColor">天</em><b id="hour">{hour}</b>:<b id="min">{minute}</b>:<b id="sec">{second}</b></span>'.substitute({title: timeInfoTitle, day: daysold, hour: hrsold<10?'0'+hrsold:hrsold, minute: minsold<10?'0'+minsold:minsold, second: seconds<10?'0'+seconds:seconds});
	$("#time").html(timeInfo);
	
}
